﻿using BLL.DTO.RecipeDto;
using DAL.Service;
using Helper;
using HZY.Framework.DependencyInjection;
using Mapster;
using Model;
using Model.Entity;
using Model.EntityInfo;

namespace BLL.Manager
{
    public class RecipeManager : IScopedSelfDependency
    {
        private readonly RecipeService _recipeService;

        public RecipeManager(RecipeService recipeService)
        {
            _recipeService = recipeService;
        }

        /// <summary>
        /// 获取配方列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<BaseResult<ResPageData<RecipeInfoModel>>> GetRecipeLidtAsync(RecipeListDto query)
        {
            return await _recipeService.GetRecipeLidtAsync(query.Code, query.Name, query.Page, query.PageSize);
        }
        /// <summary>
        /// 新增配方
        /// </summary>
        /// <param name="recipeDto"></param>
        /// <returns></returns>
        public async Task<BaseResult<string>> CreateRecipeAsync(RecipeAddDto recipeDto)
        {
            RecipeEntity recipeEntity = recipeDto.Adapt<RecipeEntity>();
            return await _recipeService.CreateRecipeAsync(recipeEntity);
        }


        /// <summary>
        /// 更新配方
        /// </summary>
        /// <param name="recipeDto"></param>
        /// <returns></returns>
        public async Task<BaseResult<string>> UpdateRecipeAsync(RecipeUpdateDto recipeDto)
        {
            RecipeEntity recipeEntity = recipeDto.Adapt<RecipeEntity>();
            return await _recipeService.UpdateRecipeAsync(recipeEntity);
        }
        /// <summary>
        /// 删除用户
        /// </summary>
        /// <param name="userDto"></param>
        /// <returns></returns>
        public async Task<BaseResult<string>> DelRecipeAsync(RecipeDelDto recipeDto)
        {
            RecipeEntity recipeEntity = recipeDto.Adapt<RecipeEntity>();
            return await _recipeService.DelRecipeAsync(recipeEntity);
        }

        /// <summary>
        /// 更新或插入
        /// </summary>
        /// <param name="recipeDto"></param>
        /// <returns></returns>
        public async Task<BaseResult<string>> UpdateOrInsertRecipeAsync(List<RecipeAddDto> recipeDto)
        {
            List<RecipeEntity> recipeEntitys = recipeDto.Adapt<List<RecipeEntity>>();
            return await _recipeService.UpdateOrInsertRecipeAsync(recipeEntitys);
        }
    }
}
